package com.shop2cn.app.liveseller.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.utils.TestDataManager;
import com.shop2cn.app.liveseller.parameter.*;
import com.shop2cn.app.liveseller.service.*;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.LiveRoomShop2cnCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.livesellerShop2cn.*;
import com.ymttest.database.sqlwapper.livesellerShop2cn.LiveRoomShop2cnWapper;
/**
*获取云通信用户签名
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetUserSig{
	private static GetUserSigBean getusersigBean;
	private static GetUserSigCall getusersigCall;
	private static int sellerId ;
	private static String token ;
	private static int csId;
	private static String cstoken;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取云通信用户签名");
		try {
			sellerId = GodmchManageCallService.CreateSellerMch();
			token=AuthCallServiceV2.createToken(sellerId, "app");
			csId = GodmchManageCallService.bindClientService(
					sellerId, 1);
			cstoken = AuthCallServiceV2.createToken(csId, "app");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	@Before
	public void caseUp() {
		getusersigBean=new GetUserSigBean();
		getusersigCall=new GetUserSigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getusersigCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserSig_001() {
		Logger.start(true,"获取云通信用户签名成功");
		try {
//			getusersigBean.setUserId(1);
			getusersigCall.setData(getusersigBean);
			String head="accesstoken="+token;
			Logger.debug("ymt-pars:"+ head);
			getusersigCall.addHeader("ymt-pars", head);
			getusersigCall.callService();			
//			Logger.verifyEquals("200", getusersigCall.getString("code"), "判断code是否为200");
			String usersig=getusersigCall.getJsonObject().get("userSig").toString();
			String imAppId=getusersigCall.getJsonObject().get("imAppId").toString();
			//disconf 配置 integration.properties   im.appId
			Logger.verifyNotNull(imAppId, "验证imAppId非空");
			Logger.verifyNotNull(usersig, "验证usersig非空");
//			Logger.verifyEquals(usersig.length()>200, true, "usersig长度大于200");
			Logger.debug(usersig);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetUserSig_002() {
		Logger.start(true,"不输入userid失败");
		try {
			getusersigCall.setData(getusersigBean);
			getusersigCall.callService();			
			Logger.verifyEquals("400", getusersigCall.getString("code"), "判断code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//seller没有游客
	public void Tc_GetUserSig_003() {
		Logger.start(true,"游客获取云通信用户签名成功");
		try {
			getusersigBean.setUserId(0);
			getusersigBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			getusersigCall.setData(getusersigBean);
			String head="accesstoken="+token;
			Logger.debug("ymt-pars:"+ head);
			getusersigCall.addHeader("ymt-pars", head);
			getusersigCall.callService();			
			String usersig=getusersigCall.getJsonObject().get("userSig").toString();
			String visitorId=getusersigCall.getJsonObject().get("visitorId").toString();
			Logger.verifyNotNull(usersig, "验证usersig非空");
			Logger.verifyEquals(usersig.length()>200, true, "usersig长度大于200");
			Logger.debug(usersig);
			Map m = new LiveRoomShop2cnWapper().selectLivevisitorById(getusersigBean.getDeviceId()).get(0);
			Logger.verifyEquals(visitorId, "-"+m.get("Id"), "验证Id");
			Logger.debug(m);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//seller没有游客
	public void Tc_GetUserSig_004() {
		Logger.start(true,"同设备游客重复获取云通信用户签名成功");
		try {
			getusersigBean.setUserId(0);
			getusersigBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			getusersigCall.setData(getusersigBean);
			String head="accesstoken="+token;
			Logger.debug("ymt-pars:"+ head);
			getusersigCall.addHeader("ymt-pars", head);
			getusersigCall.callService();			
			String visitorId=getusersigCall.getJsonObject().get("visitorId").toString();
			getusersigCall.callService();	
			String visitorId2=getusersigCall.getJsonObject().get("visitorId").toString();
			Logger.verifyEquals(visitorId, visitorId2, "验证Id");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserSig_005() {
		Logger.start(true,"客服获取云通信用户签名成功");
		try {
//			getusersigBean.setUserId(1);
			getusersigCall.setData(getusersigBean);
			String head="accesstoken="+cstoken;
			Logger.debug("ymt-pars:"+ head);
			getusersigCall.addHeader("ymt-pars", head);
			getusersigCall.callService();			
//			Logger.verifyEquals("200", getusersigCall.getString("code"), "判断code是否为200");
			String usersig=getusersigCall.getJsonObject().get("userSig").toString();
			String imAppId=getusersigCall.getJsonObject().get("imAppId").toString();
			//disconf 配置 integration.properties   im.appId
			Logger.verifyNotNull(imAppId, "验证imAppId非空");
			Logger.verifyNotNull(usersig, "验证usersig非空");
//			Logger.verifyEquals(usersig.length()>200, true, "usersig长度大于200");
			Logger.debug(usersig);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}